/*
 * =====================================================================================
 *
 *       Filename:  1008_mayacalendar.cc
 *
 *    Description:  convert the date represented by haab to Tzolkin
 *
 *        Version:  1.0
 *        Created:  09/11/2012 12:11:27 AM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Regan (), lcqhigh@gmail.com
 *        Company:  
 *
 * =====================================================================================
 */
#include	<stdio.h>
#include	<stdlib.h>
#include    <map>
#include	<string>

using std::string;
using std::map;

static std::map<string, int> habbMonthMap;

void initMap()
{
   habbMonthMap["pop"] = 1;
   habbMonthMap["no"] = 2;
   habbMonthMap["zip"] = 3;
   habbMonthMap["zotz"] = 4;
   habbMonthMap["tzec"] = 5;
   habbMonthMap["xul"] = 6;

   habbMonthMap["yoxkin"] = 7;
   habbMonthMap["mol"] = 8;
   habbMonthMap["chen"] = 9;

   habbMonthMap["yax"] = 10;
   habbMonthMap["zac"] = 11;
   habbMonthMap["ceh"] = 12;
   habbMonthMap["mac"] = 13;
   habbMonthMap["kankin"] = 14;
   habbMonthMap["muan"] = 15;

   habbMonthMap["pax"] = 16;
   habbMonthMap["koyab"] = 17;
   habbMonthMap["cumhu"] = 18;
   habbMonthMap["uayet"] = 19;
}

static string TzolkinDayName[] = 
{
    "imix","ik","akbal","kan","chicchan","cimi",
    "manik","lamat","muluk","ok","chuen","eb",
    "ben","ix","mem","cib","caban","eznab",
    "canac", "ahau" 
};

static const int  habbCycle = 365;
static const int  TzolkinCycle = 260; //least common multiple

int main(int argc, char *argv[])
{
    initMap();
    char dayStr[4] = {'\0'};
    char mothStr[16] = {'\0'};
    int  year;
    int N;
    while (scanf("%d", &N) == 1)
    {
        printf ( "%d\n", N);
        for (int k = 0; k < N; ++k)
        {
           scanf("%s%s%d", dayStr, mothStr, &year); 
           int dayNo = strtol(dayStr, NULL, 10);
           int month = habbMonthMap[mothStr];
           //printf ( "debug day:%d, month:%d, year:%d\n", dayNo, month, year);
           int totaldays = habbCycle * year + 20 * (month-1) + dayNo + 1;
           int TzolkinYearNo = totaldays / TzolkinCycle;
           int remain = totaldays % TzolkinCycle;
		   //remain may be zero
		   if (remain == 0)
		   {
			 --TzolkinYearNo;
			 remain = 260;
		   }
           int TzolkinMonth = remain % 13;
           if (TzolkinMonth == 0)
               TzolkinMonth = 13;
           int dayidx = remain % 20;
           if (dayidx == 0)
               dayidx = 20;
           string zolkinDayName = TzolkinDayName[dayidx-1];
           printf ( "%d %s %d\n", TzolkinMonth, zolkinDayName.c_str(), TzolkinYearNo);
        }
    }
}
